package _postgresql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author huangya
 * @date 2025/5/16
 */
public class PostgresqlDemo {
    public static void main(String[] args) {
        // 数据库URL, 用户名, 密码
        String url = "jdbc:postgresql://pc-uf6qt18r1ibb7b735-public.rwlb.rds.aliyuncs.com:5432/nebula_rag";
        String user = "nebula_rag";
        String password = "!Pwd@2025Banma";

        try {
            // 加载JDBC驱动
            Class.forName("org.postgresql.Driver");

            // 建立连接
            Connection conn = DriverManager.getConnection(url, user, password);

            // 创建Statement对象
            Statement stmt = conn.createStatement();

            // 执行SQL查询
            ResultSet rs = stmt.executeQuery("SELECT * FROM delivery_v_category_raw");

            // 处理结果集
            while (rs.next()) {
                System.out.println(rs.getString("main_cate_name"));
            }

            // 关闭资源
            rs.close();
            stmt.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
